package com.atmc.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

/**
 * @BelongsProject: SpringCloud1216
 * @BelongsPackage: com.com.atmc.interceptor
 * @Author: chuyings
 * @CreateTime: 2022-11-03  21:49
 * @Version: 1.0
 */
//@Component
//public class FeignInterceptor implements RequestInterceptor {
//
//    @Override
//    public void apply(RequestTemplate requestTemplate) {
//        //1.拿到上一层的header里的token令牌
//        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
//        if (requestAttributes !=null){
//            HttpServletRequest request=((ServletRequestAttributes)requestAttributes).getRequest();
//            if (request !=null){
//                Enumeration<String> headerNames = request.getHeaderNames();
//                while(headerNames.hasMoreElements()){
//                    String headerName = headerNames.nextElement();
//                    if (headerName.equalsIgnoreCase("token")){
//                        String jwt = request.getHeader(headerName);
//        //2.将jwt放在openfeign远程调用服务中
//                    }
//                }
//            }
//        }
//    }
//}
